<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>用户登录</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-3.3.1.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <script>
        $(function () {
            /*var search= location.search;
            var empId = search.split("=")[1];
            alert(empId);*/
            $.get("findEmp",function (data) {
                if(data==null){
                    alert("请先登录！");
                    location.href="login.html";
                }else{
                   $("#empId").val(data.empId);
                   $("#empId").attr("disabled","disabled");
                }
            });

            $("#btn_sub").click(function () {
                var empId = $("#empId").val();
                var oldpassword = $("#oldpassword").val();
                var newpassword = $("#newpassword").val();
                //alert(empId);
                $.get("updatePassword",{empId:empId,oldpassword:oldpassword,newpassword:newpassword},function (data) {
                    if(data.flag){
                        alert("设置成功！请重新登录！");
                        $.get("exit",function (data) {

                        });
                        location.href="login.html";
                    }else {
                        $("#errorMsg").html(data.errorMsg);
                    }
                });
            });

        });


    </script>
</head>
<body>
<div class="container" style="width: 400px;">
    <h3 style="text-align: center;">修改密码</h3>
    <form id="update_form" action="" method="post" accept-charset="utf-8">
        <div class="form-group">
            <label for="empId">用户名：</label>
            <input type="text" name="empId" class="form-control" id="empId" placeholder="请输入用户名"/>
        </div>

        <div class="form-group">
            <label for="oldpassword">原来密码：</label>
            <input type="password" name="oldpassword" class="form-control" id="oldpassword" placeholder="请输入密码"/>
        </div>
        <div class="form-group">
            <label for="newpassword">新密码：</label>
            <input type="password" name="newpassword" class="form-control" id="newpassword" placeholder="请输入密码"/>
        </div>
        <hr/>
        <div class="submit_btn" style="text-align: center;">
            <button type="button" class="btn btn-primary" id="btn_sub">提交</button>
        </div>
    </form>

    <!-- 出错显示的信息框 -->
    <div class="alert alert-warning alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" >
            <span>&times;</span>
        </button>
        <strong id="errorMsg"></strong>
    </div>
</div>
</body>
</html>